import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:lcapp/config/const_config.dart';
import 'package:lcapp/model/toast/toast.dart';
import 'package:lcapp/widget/asr_app_bar.dart';
import 'package:package_info_plus/package_info_plus.dart';

class MinAboutMinPage extends StatefulWidget {
  const MinAboutMinPage({Key? key}) : super(key: key);

  @override
  _MinAboutMinPageState createState() => _MinAboutMinPageState();
}

class _MinAboutMinPageState extends State<MinAboutMinPage> {
  TextEditingController controller = TextEditingController();
  String version = '1.0.0';

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getVersion();
  }

  void getVersion()async{
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    if(mounted){setState(() {
      version = packageInfo.version;
    });}
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: bgColor,
      appBar: AsrAppBar(
        titleText: '关于我们',
      ),
      body: Container(
        width: 1.sw,
        padding: EdgeInsets.symmetric(vertical: 60.w),
        child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Container(
                child: Image.asset('assets/icon/icon.png',width: 120.w,),
              ),
              SizedBox(height: 30.w,),
              GestureDetector(
                child: Container(
                  child: Text('V$version',style: TextStyle(
                      color: Colors.black,
                      fontSize: 26.sp,
                      fontWeight: FontWeight.w600
                  ),),
                ),
              ),
              SizedBox(height: 50.w,),
              Container(
                padding: EdgeInsets.symmetric(horizontal: 30.w),
                child: Text('粮策隶属于德州微派网络科技有限公司。粮策App是提供和粮食贸易相关的产品和服务平台。通过线上平台将粮食供应商和粮食加工企业紧密联系在一起，同时提供物流运输、仓储、供应链、金融、大数据分析等第三方服务。赋能传统粮食贸易行业，提高其运转效率，推动产业链数字化发展。',
                  style: TextStyle(
                    color: Colors.black,
                    fontSize: 26.sp,
                    fontWeight: FontWeight.w600,
                    height: 2
                ),),
              ),
              SizedBox(height: 150.w,),
              GestureDetector(
                onTap: (){
                  Baseurl = 'https://app.liangce.cc';
                  showToast('正式环境');
                },
                onDoubleTap: (){
                  SmartDialog.show(builder: (BuildContext context) {
                    return Container(
                      padding: EdgeInsets.all(30.w),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Container(
                            margin: EdgeInsets.only(top: 15.w),
                            height: 100.w,
                            child: TextField(
                              controller: controller,
                              textInputAction: TextInputAction.done,
                              maxLines: 1,
                              // cursorColor: Color(0xFFFF3000),
                              // keyboardType: TextInputType.number,
                              autocorrect: true,
                              autofocus: false,
                              decoration:  InputDecoration(
                                contentPadding: EdgeInsets.only(left: 17.w),
                                hintText: "局域网IP如：http://192.168.16.93:8085",
                                hintStyle: TextStyle(
                                  color: const Color(0xFFAEAEAE),
                                  fontSize: 26.sp,
                                  fontWeight: FontWeight.w500,
                                ),
                                counterText: "",
                                border: const OutlineInputBorder(
                                  borderSide: BorderSide.none,
                                ),
                                fillColor: const Color(0xFFF8F8F8),
                                filled: true,
                              ),
                            ),
                          ),
                          GestureDetector(
                            onTap: (){
                              Baseurl = controller.text.trim();
                              showToast('开发环境');
                              SmartDialog.dismiss();
                            },
                            child: Container(
                              height: 100.w,
                              width: 400.w,
                              margin: EdgeInsets.symmetric(vertical: 30.w),
                              color: Colors.red,
                              alignment: Alignment.center,
                              child: Text('确定'),
                            ),
                          ),
                          GestureDetector(
                            onTap: (){
                              SmartDialog.dismiss();
                            },
                            child: Container(
                              height: 100.w,
                              width: 400.w,
                              color: Colors.yellow,
                              alignment: Alignment.center,
                              child: Text('取消'),
                            ),
                          )
                        ],
                      ),
                    );
                  });
                },
                child: Container(
                  margin: EdgeInsets.symmetric(vertical: 40.w),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Container(
                        height: 2,
                        width: 170.w,
                        color: Color(0xffE9E8E9),
                      ),
                      SizedBox(width: 30.w,),
                      Text('粮策数据',style: TextStyle(
                          fontSize: 34.sp,
                          color: Color(0xff1A051D),
                          fontWeight: FontWeight.w600
                      ),),
                      SizedBox(width: 30.w,),
                      Container(
                        height: 2,
                        width: 170.w,
                        color: Color(0xffE9E8E9),
                      ),
                    ],
                  ),
                ),
              ),
              Container(
                child: RichText(
                  maxLines: 2,
                  softWrap: true,
                  text: TextSpan(
                    text: '',
                    style: TextStyle(
                      fontSize: 24.w,
                      color: const Color(0xff999999),
                    ),
                    children: <TextSpan>[
                      TextSpan(
                        text: '《用户协议》',
                        style:  TextStyle(
                          color: const Color(0xff224D79),
                          fontSize: 24.w,
                        ),
                        recognizer: TapGestureRecognizer()
                          ..onTap = () {
                            Navigator.of(context).pushNamed('H5Page',arguments: {
                              'url':protocolURL,
                              'title':'《用户协议》'
                            });
                          },
                      ),
                      TextSpan(
                        text: '和',
                        style: TextStyle(
                          fontSize: 24.w,
                          color: const Color(0xff999999),
                        ),),
                      TextSpan(
                        text: '《隐私协议》',
                        style: TextStyle(
                          color: const Color(0xff224D79),
                          fontSize: 24.w,
                        ),
                        recognizer: TapGestureRecognizer()
                          ..onTap = () async {
                            Navigator.of(context).pushNamed('H5Page',arguments: {
                              'url':privacyURL,
                              'title':'《隐私协议》'
                            });
                          },
                      ),
                    ],
                  ),
                  textAlign: TextAlign.left,
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
